package com.inspur.edp.web.formmetadata.i18n.component.strategy.i18nresourcestrategy;

import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItemCollection;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameFactory;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameType;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.IComponentNameStrategy;
import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItem;
import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItemCollection;
import com.inspur.edp.web.common.utility.StringUtility;
import com.inspur.edp.web.formmetadata.i18n.I18nResourceItemManager;
import com.inspur.edp.web.formmetadata.i18n.component.ComponentUtility;
import com.inspur.edp.web.formmetadata.i18n.component.I18nResourceUtility;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameFactory;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameType;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.IComponentNameStrategy;
import com.inspur.edp.web.formmetadata.i18n.constant.I18nResourceConstant;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
/**
 * VUE输入类构件提取
 * @author wangzhiyuan
 */
public class FormGroupI18nResourceStrategy extends AbstractI18nResourceStrategy {
    @Override
    protected String getComponentName(HashMap<String, Object> component)  {
        IComponentNameStrategy componentNameStrategy = ComponentNameFactory.getInstance().creatComponentNameStrategy(ComponentNameType.LABEL);
        if (componentNameStrategy == null) {
            return null;
        }

        return componentNameStrategy.getComponentName(component);
    }
    //提取VUE输入类，枚举项多语
    @Override
    protected I18nResourceItemCollection extractAttributeI18nResourceItemCollection(String i18nResourceItemBaseId, HashMap<String, Object> currentComponent) {
        I18nResourceItemCollection i18nResourceItemCollection = new I18nResourceItemCollection();
        HashMap<String, Object> editors =(HashMap<String, Object>) currentComponent.get("editor");
        if(!editors.isEmpty()&&editors.containsKey("data")){
            List<Object> datas=(List<Object>) editors.get("data");
            String currentComponentType = ComponentUtility.getInstance().getType(currentComponent);
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            for (Object o : datas) {
                HashMap<Object, Object> data = (HashMap<Object, Object>) o;
                String generatedComponentId =  currentComponentId + "/editor/data/" + (String)(data.get("value"));
                I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, (String)(data.get("name")), (String)(data.get("name")));
                this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);

            }
        }
        if(!editors.isEmpty()&&editors.containsKey("placeholder")){

            String currentComponentType = ComponentUtility.getInstance().getType(currentComponent);
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
                String generatedComponentId =  currentComponentId + "/editor/placeholder"  ;
                I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, (String)(editors.get("placeholder")),(String)(editors.get("placeholder")));
                this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);
        }
        if(!editors.isEmpty()&&editors.containsKey("alt")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            String generatedComponentId =  currentComponentId + "/editor/alt"  ;
            I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, (String)(editors.get("alt")),(String)(editors.get("alt")));
            this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);
        }
        if(!editors.isEmpty()&&editors.containsKey("title")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            String generatedComponentId =  currentComponentId + "/editor/title"  ;
            I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, (String)(editors.get("title")),(String)(editors.get("title")));
            this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);
        }
        if(editors.containsKey("dialog")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            LinkedHashMap<String,Object> dialog= (LinkedHashMap<String, Object>) editors.get("dialog");
            String title= (String) dialog.get("title");
            String childComponentId = currentComponentId +   "/dialog/title";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, title, title);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);

        }

        if(editors.containsKey("formatValidation")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            LinkedHashMap<String,Object> formatValidation= (LinkedHashMap<String, Object>) editors.get("formatValidation");
            String message = (String) formatValidation.get("message");
            String childComponentId = currentComponentId +   "/formatValidation/message";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, message, message);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);
        }
        if(editors.containsKey("onLabel")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            String onLabel= (String) editors.get("onLabel");
            String childComponentId = currentComponentId +   "/onLabel";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, onLabel, onLabel);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);
        }
        if(editors.containsKey("offLabel")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            String offLabel= (String) editors.get("offLabel");
            String childComponentId = currentComponentId +   "/offLabel";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, offLabel, offLabel);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);
        }
        if(editors.containsKey("label")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            String offLabel= (String) editors.get("label");
            String childComponentId = currentComponentId +   "/editor/label";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, offLabel, offLabel);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);
        }


        return i18nResourceItemCollection;
    }
}